const {ccclass, property} = cc._decorator;

import birdControl from './birdControl'

@ccclass
export default class BackgroundMove extends cc.Component {

    // LIFE-CYCLE CALLBACKS:
    // 速度
    @property(cc.Integer)
    speed: number = 0
    // 图片宽度
    @property(cc.Integer)
    width: number = 0
    // 小鸟
    @property(cc.Node)
    bird: cc.Node

    onLoad () {}

    start () {
        this.touchScreen()
    }
    // 触摸屏幕方法
    touchScreen() {
        this.node.on(cc.Node.EventType.TOUCH_START, (e: cc.Touch)=> {
            this.bird.getComponent(birdControl).fly();
        }, this)
    }

    update (dt) {
        let childs = this.node.children;
        for(let i of childs) {
            i.x -= this.speed * dt;
            if (i.x < -this.width) {
                i.x += this.width * 2 - 3; 
            }
        }
        
    }
}
